import { Component, OnInit } from '@angular/core';

declare const moment;

@Component({
    selector: 'my-calendar',
    templateUrl: './calendar.component.html',
    styleUrls: ['./calendar.component.scss']
})
export class MyCalendarComponent implements OnInit {
    weeks: Array<string>;
    monthYear: string;
    days: Array<number> = [];
    today: number;

    constructor() {
        this.today = moment().date();
        this.weeks = ['日', '一', '二', '三', '四', '五', '六'];
        this.monthYear = moment().format('MMMM GGGG');
    };

    ngOnInit() {
        let dayObj = moment().toObject();
        let i = 1;
        let circle = moment().daysInMonth();

        const firstDayIndex = moment().startOf('month').day();

        if (firstDayIndex === 0) {
            for (; i <= circle; i++) {
                this.days.push(i);
            };
        } else {
            let fill = new Array(firstDayIndex);    // 创建4个空白元素数组
            this.days = this.days.concat(fill);     // 填充进日期

            for (; i <= circle; i++) {
                this.days.push(i);
            };
        }

    }

}
